package com.tsunami.swagger2;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * swagger 包扫描配置
 *
 * @author lx
 */
@Import({
        Swagger2Configuration.class
})
@EnableConfigurationProperties(SwaggerProperties.class)
public class SwaggerAutoConfiguration {

    @Autowired
    SwaggerProperties swaggerProperties;


    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder()
                .group(swaggerProperties.getGroup())
                .pathsToMatch(swaggerProperties.getBasePackage())
                .build();
    }

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(swaggerProperties.getTitle())
                        .description(swaggerProperties.getDescription())
                        .version(swaggerProperties.getVersion())
                        .contact(swaggerProperties.getContact())
                        .license(new License().name(swaggerProperties.getLicense())
                                .url(swaggerProperties.getLicenseUrl())));
    }
}
